<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .gray {
        color: #808080;
    }

    .black {
        color: #000;
    }
</style>
<script>
    window.onload = function () {

        var txtSearch = document.getElementById('txtSearch');
        txtSearch.onfocus = function () {
            if (this.value === '请输入关键字') {
                this.value = '';
                this.className = 'black';
            }
        }
        txtSearch.onblur = function () {
            if (this.value.length === 0 || this.value === '请输入关键字') {
                this.value = '请输入关键字';
                this.className = 'gary';
            }
        }
    }
</script>


<body>
    <input type="text" name="" id="txtSearch" value="请输入关键字" class="gray">
    <input type="button" value="搜索">
</body>

</html>